Repository navigation
fix(sqlite): backfill _sqlite_rowid slot on pre-existing rel tables - #143
Merged
Merged
Conversation
One SQLite WAL commit now maps to one Ladybug transaction: the batch's statements plus its cursor advance commit atomically. A mid-tick failure (e.g. a binder error on one edge table) leaves no partial rows behind, and the next tick replays whole batches idempotently. - applyBatchTx wraps BEGIN .. batch .. cursor .. COMMIT with ROLLBACK on any statement failure; stats only count committed work. - Cursor advances per batch instead of once at tick end, so crash recovery resumes from the last committed SQLite commit. - DDL stays outside the transaction (replay-safe: IF NOT EXISTS / one-shot shadow healing).
Edge upserts address rows by the _sqlite_rowid slot (delete-by-slot + CREATE), and tables the sync creates carry it from buildRelDdl — but explicitly mapped pre-existing native tables don't, so the whole tick failed with 'Binder exception: Cannot find property _sqlite_rowid'. Issue ALTER TABLE <label> ADD IF NOT EXISTS _sqlite_rowid INT64 for every mapped edge table in the DDL phase (idempotent, replay-safe, and outside the per-batch transactions). Pre-sync edges read NULL — correct, they are not sync-owned; endpoint deletes still cover them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #142 — please merge #142 first; once it lands this diff shrinks to the single slot commit below. (Opened against
mainbecause the #142 branch only exists on the fork.)Problem. Edge upserts address rows by the
_sqlite_rowidslot (MATCH ()-[e:Label {_sqlite_rowid}] DELETE+CREATE … {_sqlite_rowid}). Tables the sync itself creates carry the slot frombuildRelDdl, but explicitly mapped pre-existing native tables (e.g.MentionedIn/RelatesTo/ConflictsWith) don't — so the first edge statement of any tick failed withBinder exception: Cannot find property _sqlite_rowid, and (pre-#142) the already-committed node rows were left behind as partial state.Change (
sqlite/src/function/sync_engine.cpp, DDL phase): for every mapped edge table,ALTER TABLE <label> ADD IF NOT EXISTS _sqlite_rowid INT64. Idempotent and replay-safe; runs with the other DDL outside the per-batch transactions. Pre-sync edges read NULL for the slot — correct, they are not sync-owned, and endpoint-based deletes still cover them.Validation (consumer-side,
ladybug-memory-rssqlite-first path through the real engine + this build):via=extension, no fallback: 1 memory, 2 entities, 2 mentions, cursor advanced, second tick reports caught up.